//
//  LHPictureDetailCell.m
//  Project_B
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "LHPictureDetailCell.h"

@implementation LHPictureDetailCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    UIScrollView *scroll = [UIScrollView new];
    scroll.maximumZoomScale = 3.0;
    scroll.minimumZoomScale = 0.3;
    [self.contentView addSubview:scroll];
    [scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT));
        
    }];
    
    _image = [UIImageView new];
    _image.backgroundColor = [UIColor blackColor];
//    _image.frame = CGRectMake(0, -30, SCREEN_WIDTH, SCREEN_HEIGHT-120);
    _image.contentMode = UIViewContentModeScaleAspectFit;
    _image.userInteractionEnabled = YES;
    [scroll addSubview:_image];
    [_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(-100));
        make.left.equalTo(@0);
        make.size.mas_equalTo(scroll);
        
    }];

    //背景大的ScrollView
    _contentS = [UIScrollView new];
    _contentS.backgroundColor = [UIColor clearColor];
    _contentS.bounces = NO;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    tap.numberOfTapsRequired = 2;
    [tap addTarget:self action:@selector(tapAction)];
    [_contentS addGestureRecognizer:tap];
    //去掉滚动条
    _contentS.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:_contentS];
    [_contentS mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.contentView);
        make.top.equalTo(@360);
        make.left.equalTo(@0);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 160));
    }];
    
    
    
    _aview = [UIView new];
    _aview.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.400];
    [self.contentS addSubview:_aview];
    [_aview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentS);
        make.top.equalTo(@60);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 200));
        
    }];
    //标题
    _titleLabel = [UILabel new];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.font = [UIFont systemFontOfSize:20*ADAPT_FONT];
    _titleLabel.textColor = [UIColor whiteColor];
    [_aview addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@8);
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-80, 30));
        
    }];
    
    //页数
    _pageLabel = [UILabel new];
    _pageLabel.textColor = [UIColor whiteColor];
    _pageLabel.font = [UIFont systemFontOfSize:20];
    [_aview addSubview:_pageLabel];
    [_pageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel);
        make.right.equalTo(@(-8));
        make.size.mas_equalTo(CGSizeMake(50, 30));
    }];
    
    //内容
    _contentLabel = [UILabel new];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.font = [UIFont systemFontOfSize:14];
    _contentLabel.textColor = [UIColor colorWithWhite:0.874 alpha:1.000];
    _contentLabel.numberOfLines = 0;
    [_aview addSubview:_contentLabel];

}

#pragma mark ** 双击放大
- (void)tapAction
{
    NSLog(@"aaaaaaaaaaaa");
}

- (void)setModel:(LHPictureDetailModel *)model
{
    
    //标题
    _titleLabel.text = model.setname;
    
    //图片
    [_image sd_setImageWithURL:[NSURL URLWithString:model.imgurl] placeholderImage:PLACEHOLDER_IMAGE];
    
    //scrollview偏移量

    _contentS.contentSize = CGSizeMake(SCREEN_WIDTH, model.labelH+30-100+model.labelH+30);
    [_contentS mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.bottom.equalTo(@(-100));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, model.labelH+30));
        
    }];
    
    if (model.labelH+30-100 < 0) {
        [_aview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.offset(120);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, model.labelH+30));
        }];
    }else{
        [_aview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.offset(model.labelH+30-100);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, model.labelH+30));
        }];
    }


    

    
    //内容
    if (!model.imgtitle) {
        _contentLabel.text = [NSString stringWithFormat:@"%@",model.note];

    }else{
        _contentLabel.text = [NSString stringWithFormat:@"%@ %@",model.imgtitle,model.note];

    }
    
    [_contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel);
        make.top.equalTo(_titleLabel.mas_bottom);
        make.right.offset(-8);
    }];

}
@end
